package org.hot100_6.leetcode1;

import java.util.HashMap;

public class Solution3 {
    public int[] twoSum(int[] nums, int target) {

        int[] res = new int[2];

        HashMap<Integer, Integer> hashMap = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            hashMap.put(nums[i], i);
        }

        for (int i = 0; i < nums.length; i++) {
            int num = target - nums[i];
            if (hashMap.containsKey(num) && hashMap.get(num) != i) {
                res[0] = i;
                res[1] = hashMap.get(num);
            }
        }


        return res;
    }
}
